package com.henghe.frame.mq.util;

import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Description:
 * Author: LiuWenQing
 * Datetime: 2023/3/22 13:15
 */
public class PatternUtil {

    public static List<List<String>> handleQueue(String queues){
        if(StringUtils.isEmpty(queues))
            return null;

        List<List<String>> list = new ArrayList<>();
        Pattern p = Pattern.compile("(\\[[^\\]]*\\])");
        Matcher m = p.matcher(queues);
        while (m.find()){
            String substring = m.group().substring(1, m.group().length() - 1);
            if(!StringUtils.isEmpty(substring)){
                list.add(Arrays.asList(substring.replaceAll("\"","").split(",")));
            }
        }
        return list;
    }
}
